﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Configuration;
using Framework;
using ISSMoviePlex.DAL.Models;

namespace ISSMoviePlex.DAL.Repositories
{
    public class MovieRepository : BaseRepository<int, Movie, MovieRepository>
    {
        private GenreRepository _genreRepository;

        public override void ResolveDependencies()
        {
            _genreRepository = GenreRepository.Instance;
            _genreRepository.IsUnitTest = IsUnitTest;
            _genreRepository.Initialize();
        }

        public Movie FindFirstMovieByTitle(string title)
        {
            return Context.Movies.FirstOrDefault(m => m.MovieName.ToLower().Contains(title));
        }

        public IEnumerable<Movie> FindMoviesByTitle(string title)
        {
            return Context.Movies.Where(m => m.MovieName.ToLower().Contains(title));
        }

        public override Movie FindById(int id)
        {
            return Context.Movies.SingleOrDefault(m => m.MovieId == id);
        }

        public IEnumerable<Movie> GetAllMoviesByGenre(string genre)
        {
            var g = _genreRepository.FindByName(genre);
            if (g != null) return g.Movies;
            return new List<Movie>();
        }

    }
}
